from django import template
from decimal import Decimal

register = template.Library()

@register.filter
def sub(value, arg):
    """从value中减去arg的值"""
    try:
        # 确保value和arg都是数值
        if isinstance(value, str):
            value = float(value)
        if isinstance(arg, str):
            arg = float(arg)
        return value - arg
    except (ValueError, TypeError):
        return 0 